<?php 
define('IN_QY',true);
session_start();
require("include/common.inc.php");
if(!$_COOKIE['userid']){
    echo "<script type='text/javascript'>location.href='/wap/mlogin.php';</script>";
    exit;
}

	$sqlmo = "update tbl_taorder set is_pay=2 where is_pay=0 AND uid=".$_COOKIE['userid'];
    $res=mysql_query($sqlmo);
	
	
//未支付订单判断
$sql = "select * from tbl_taocart where userid='".$_COOKIE['userid']."' and isorder=0 and is_tax=1";
$query = mysql_query($sql);
$rowcart= mysql_fetch_array($query);
if (!$rowcart) {
  echo "<script type='text/javascript'>alert('您的海淘购物车是空的!');history.go(-1);</script>";
  exit;
}
//订单号
$order_id = $_COOKIE['userid']."a".date('YmdHis',time());

$sql = "select t1.*,t2.typeid,t2.ggnum,t2.entitle,t2.encode from tbl_taocart t1 inner join tbl_taospp t2 on t1.goodsid=t2.id  where t1.userid='".$_COOKIE['userid']."' and t1.isorder=0 and t1.is_tax=1 group by t1.id";
$query = mysql_query($sql);   
while($row=mysql_fetch_array($query)){

    //写订单表
    $sql = "insert into tbl_taorder values (
	0,
	'".$_COOKIE['userid']."',
	'".$row['goodsid']."',
	'".$order_id."',
	'".$row['goodspri']."',
	'".$row['vip_price']."',	
	'".$row['goodsnum']."',
	'".$row['buyunit']."',
	'".$row['ggnum']."',
	0,
	'".time()."',
	0,
	0,
	0,
	0,
	0,
	'".$totpri."',
	0,
	0,
	0,
	0,
	'".$row['buyunit']."',
	0,
	0,0)";
    mysql_query($sql);
}
//运费



//改购物车状态

  //$sql = "update tbl_taocart set isorder=1 where userid='".$_COOKIE['userid']."' and isorder=0 and is_tax=1";
//  $resy=mysql_query($sql);


setcookie("dindanid",$order_id,time()+(3600*8*1*1),"/");   




    echo "<script type='text/javascript'>location.href='htdjxiadan.php'</script>";
    exit;

